<template>
  <div class="card" @click="handleClick">
    <div class="card-image">
      <img :src="cardData.image" :alt="cardData.title" />
    </div>
    <div class="card-content">
      <h3>{{ cardData.title }}</h3>
      <p>{{ cardData.description }}</p>
      <span class="card-tag" v-if="cardData.tag">{{ cardData.tag }}</span>
    </div>
  </div>
</template>

<script setup>
const props = defineProps({
  cardData: {
    type: Object,
    required: true,
    default: () => ({})
  }
});

const emit = defineEmits(['cardClick']);

const handleClick = () => {
  emit('cardClick', props.cardData.id);
};
</script>

<style scoped>
.card {
  position: relative;
  /* border-radius: 8px; */
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
  cursor: pointer;
  height: 300px;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.card-image {
  width: 100%;
  height: 0;
  padding-bottom: 100%; /* 正方形图片 */
  position: relative;
}

.card-image img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-content {
  /* position: absolute; */
  left: 0;
  bottom: 0;
  /* width: 100%; */
  padding: 16px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
  color: white;
}

.card-content h3 {
  margin: 0 0 8px 0;
  font-size: 1.2rem;
  font-weight: 600;
  z-index: 1;
}

.card-content p {
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.9;
  display: -webkit-box;
  /* -webkit-line-clamp: 2; */
  -webkit-box-orient: vertical;
  /* overflow: hidden; */
   word-wrap: break-word;  /* 允许长单词换行 */
  overflow-wrap: break-word; /* 更现代的属性 */
  z-index: 1;

}

.card-tag {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 10px;
  background-color: #ff4757;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: bold;
}
</style>